﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace Cqrs.CodeGeneration.CSharp
{
    public class DomainProperty
    {
        public string Name { get; set; }
        public string Type { get; set; }

        public static List<DomainProperty> ConvertXElementsToDomainProperties(
            IEnumerable<XElement> domainPropertXmlElements)
        {
            List<DomainProperty> domainProperties = new List<DomainProperty>();
            foreach (XElement domainProperty in domainPropertXmlElements)
            {
                domainProperties.Add(
                    new DomainProperty() { 
                        Name = domainProperty.Name.LocalName, Type = domainProperty.Attribute("Type").Value });
            }
            return domainProperties;
        }

        public static XElement ConvertDomainPropertiesToXElement(IEnumerable<DomainProperty> domainProperties)
        {
            XElement xelement = new XElement("DomainProperties");
            foreach (DomainProperty domainProperty in domainProperties)
            {
                XElement propXml = new XElement(domainProperty.Name);
                propXml.Add(new XAttribute("Type", domainProperty.Type));
                xelement.Add(propXml);
            }
            return xelement;
        }
    }
}
